package com.yj.timecapsule.controller.diaries;

import com.yj.timecapsule.common.response.CommonResponseType;
import com.yj.timecapsule.common.response.PageResponse;
import com.yj.timecapsule.entity.diaries.dto.DiariesDto;
import com.yj.timecapsule.entity.diaries.dto.DiariesQueryDto;
import com.yj.timecapsule.entity.diaries.vo.DiariesDetailVo;
import com.yj.timecapsule.entity.diaries.vo.DiariesVo;
import com.yj.timecapsule.service.diaries.DiariesService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/diaries")
public class DiariesController {
    @Resource
    private DiariesService diariesService;
    @PostMapping("/load")
    public CommonResponseType<PageResponse<DiariesVo>> load(@RequestBody DiariesQueryDto dto){
        return CommonResponseType.success(diariesService.load(dto));
    }
    @GetMapping("/detail/{id}")
    public CommonResponseType<DiariesDetailVo> detail(@PathVariable("id") Long id){
        return CommonResponseType.success(diariesService.getDetail(id));
    }
    @PostMapping("/publication")
    public CommonResponseType<Object> publication(@RequestBody DiariesDto dto){
        diariesService.publication(dto);
        return CommonResponseType.success();
    }
    @PutMapping("/republication")
    public CommonResponseType<Object> republication(@RequestBody DiariesDto dto){
        diariesService.publication(dto);
        return CommonResponseType.success();
    }
    @DeleteMapping("/del/{id}")
    public CommonResponseType<Object> del(@PathVariable("id") Long id){
        diariesService.del(id);
        return CommonResponseType.success();
    }
}
